/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Componentes.Validators;

import javax.swing.JLabel;
import org.jdesktop.beansbinding.AbstractBindingListener;
import org.jdesktop.beansbinding.Binding;

/**
 *
 * @author luisramirezmartinez SAMI 2011
 *
 */
public class BindingMesajes extends AbstractBindingListener {
    
    private JLabel outputLabel;

    
    public BindingMesajes(JLabel outputLabel) {
        if (outputLabel == null) throw new IllegalArgumentException();
        this.outputLabel = outputLabel;
    }

    @Override
    public void syncFailed(Binding binding, Binding.SyncFailure fail) {
        String description;
        if ((fail != null) && (fail.getType() == Binding.SyncFailureType.VALIDATION_FAILED)) {
            description = fail.getValidationResult().getDescription();
        } else {
            description = "Sync failed!";
        }
        String msg = "" + binding.getName() + " " + description+"  ";
       
        outputLabel.setText(msg);
    }

    @Override
    public void synced(Binding binding) {
        String bindName = binding.getName();
        String msg = "[" + bindName + "] Synced";
             
        outputLabel.setText("");
    }

}

